/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dusin.servlet.common;

import com.tlf.dyjc5.service.PointService;
import com.tlf.dyjc5.service.RsjService;
import com.tlf.dyjc5.service.YsjService;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.dusin.commonutil.CommonUtil;
import org.dusin.commonutil.DateUtil;
import org.dusin.web.util.CommonWebUtil;
import org.dusin.web.util.ExcelUtil;
import org.dusin.web.util.TheUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 * @author tengyu
 */
public class ExcelFileCreate extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        List<Map<String, Object>> list = null;
        String fileName = "导出数据";//设置导出的文件名称        

        //PrintWriter out = response.getWriter();
        OutputStream out = response.getOutputStream();
        try {
            ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
            PointService pointService = (PointService) context.getBean("pointService");
            RsjService rsjService = (RsjService) context.getBean("rsjService");
            YsjService ysjService = (YsjService) context.getBean("ysjService");

            String currentOrgCode = (String) request.getSession().getAttribute("currentOrgCode");
            String currentOrgName = (String) request.getSession().getAttribute("currentOrgName");
            int type = Integer.parseInt((String) request.getParameter("type"));
            String basePath = this.getInitParameter("basePath");
            int startRow = 0;
            int startCol = 0;
            String[] fields = null;
            String title = null;
            String templateFile = "src/java/exceltemplat/pointdetail.xls";
            File file = new File(".");
            //System.out.println(file.getAbsolutePath());
            String path = file.getAbsolutePath();
            String lock = request.getParameter("lock");
            //System.out.println("**************************");
            switch (type) {

                case 1:
                    fileName = currentOrgName + "监测点台账汇总表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    int reportStatus = CommonWebUtil.getIntParameter(request.getParameter("reportStatus"), -1);
                    int range = CommonWebUtil.getIntParameter(request.getParameter("range"), -1);
                    String date = request.getParameter("dateTo");
                    String cmd = request.getParameter("cmd");
                    int orgLevel = currentOrgCode.length();
                    if("subnumber".equals(cmd)){
                        orgLevel +=2;
                    }                    
                    list = pointService.findNumberOfType(currentOrgCode, orgLevel,date, reportStatus, range);
                    
                    startRow = 3;
                    startCol = 0;
                    String dateStr = DateUtil.changePattern(date, "yyyyMM", "yyyy-MM");
                    String reportStr = TheUtil.getReportStr(reportStatus);
                    String rangeStr = TheUtil.getRangeStr(range);

                    fields = new String[]{"orgName", "total", "A", "B", "C", "DN", "DC", "D"};
                    title = currentOrgName + dateStr + rangeStr + reportStr + "监测点台账汇总表";
                    templateFile = basePath + "/监测点台账汇总表.xls";
                    break;
                case 2:    //所有监测点台账
                    fileName = currentOrgName + "监测点台账明细表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");
                    String cond = TheUtil.getPointSelectCondition(request);
                    list = pointService.findAll(currentOrgCode, cond, 0, 10000000);

                    for (Map<String, Object> map : list) {

                        int reportStatusTemp = (Integer) (map.get("reportStatus"));
                        if (reportStatusTemp == 1) {
                            map.put("reportStatus", "上报");
                        } else {
                            map.put("reportStatus", "观测");
                        }

                        Timestamp effectTime = (Timestamp) (map.get("effectTime"));
                        if (effectTime != null) {
                            map.put("effectTime", DateUtil.get(effectTime, "yyyy-MM-dd"));
                        }

                        Timestamp installTime = (Timestamp) (map.get("installTime"));
                        if (installTime != null) {
                            map.put("installTime", DateUtil.get(installTime, "yyyy-MM-dd"));
                        }

                        Timestamp checkTime = (Timestamp) (map.get("checkTime"));
                        if (checkTime != null) {
                            map.put("checkTime", DateUtil.get(checkTime, "yyyy-MM-dd"));
                        }
                    }

                    startRow = 6;
                    startCol = 0;
                    fields = new String[]{"company", "subCompany", "name", "pointType", "pointType2", "voltageLevelName", "upperLimit",
                        "lowerLimit", "shortName", "pointArea", "pointPosition", "stationName", "stationVoltageLevel", "userName", "publicName", "reportStatus",
                        "effectTime", "installSite", "deviceType", "manufactoryName", "model", "commTypeName", "mobileNo", "ip", "installTime", "checkTime"};
                    //title = currentOrgName + "电压监测点台账报表";
                    title = null;
                    templateFile = basePath + "/电压监测点台账报表.xls";
                    break;
                case 21:
                    fileName = "监测点台账导入模板";
                    startRow = 2;
                    startCol = 1;
                    list = new ArrayList();
                    fields = new String[]{};
                    title = null;
                    templateFile = basePath + "/download/台账导入模板.xls";
                    break;
                case 22:    //按月内启动的监测点台账
                    fileName = currentOrgName + "监测点台账明细表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");
                    cond = TheUtil.getPointSelectCondition(request);
                    cmd = request.getParameter("cmd");
                    String dateTo = request.getParameter("dateTo");
                    if("general".equals(cmd)){
                        list = pointService.findAll(currentOrgCode, cond,0, 9999);
                    }else{
                        list = pointService.findAllStartedByMonth(currentOrgCode, dateTo, cond, 0, 10000000);
                    }
                    for (Map<String, Object> map : list) {

                        Timestamp effectTime = (Timestamp) (map.get("effectTime"));
                        if (effectTime != null) {
                            map.put("effectTime", DateUtil.get(effectTime, "yyyy-MM-dd"));
                        }

                        Timestamp installTime = (Timestamp) (map.get("installTime"));
                        if (installTime != null) {
                            map.put("installTime", DateUtil.get(installTime, "yyyy-MM-dd"));
                        }

                        Timestamp checkTime = (Timestamp) (map.get("checkTime"));
                        if (checkTime != null) {
                            map.put("checkTime", DateUtil.get(checkTime, "yyyy-MM-dd"));
                        }
                    }

                    startRow = 6;
                    startCol = 0;
                    fields = new String[]{"company", "subCompany", "name", "pointType", "pointType2", "voltageLevelName", "upperLimit",
                        "lowerLimit", "shortName", "pointArea", "pointPosition", "stationName", "stationVoltageLevel", "userName", "publicName", "reportStatusCh",
                        "effectTime", "installSite", "deviceType", "manufactoryName", "model", "commTypeName", "mobileNo", "ip", "installTime", "checkTime"};
                    //title = currentOrgName + "电压监测点台账报表";
                    title = null;
                    templateFile = basePath + "/电压监测点台账报表.xls";
                    break;
                case 23:          //电压监测点台帐报表 监测点管理中
                    cond = TheUtil.getPointSelectCondition(request);
                    list = pointService.findAll(currentOrgCode, cond,0, 9999);
                    startRow = 6;
                    startCol = 0;
                    fields = new String[]{"id","company", "subCompany","shortName", "name", "pointType", "pointType2", "voltageLevelName", "upperLimit",
                        "lowerLimit", "shortName", "pointArea", "pointPosition", "stationName", "stationVoltageLevel", "userName", "publicName", "reportStatusCh",
                        "effectTime", "installSite", "deviceType", "manufactoryName", "model", "commTypeName", "mobileNo", "ip", "installTime", "checkTime"};
                    //title = currentOrgName + "电压监测点台账报表";
                    title = currentOrgName + "电压监测点台账清单";
                    templateFile = basePath + "/电压监测点台账清单.xls";
                    break;
                case 3:
                    fileName = currentOrgName + "电压监测点日报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");
                    String dateFrom = request.getParameter("dateFrom");
                    dateTo = request.getParameter("dateTo");

                    String condition = TheUtil.getPointSelectCondition(request);

                    list = rsjService.findAll(currentOrgCode, dateFrom, dateTo, condition, 0, 99999, lock);

                    startRow = 1;
                    startCol = 0;
                    fields = new String[]{"company", "subCompany", "name", "pointType", "pointType2", "rate", "upperLimitRate", "lowerLimitRate", "totalRunMin", "qualifiedMin",
                        "unqualifiedMin", "aboveUpperLimitMin", "underLowerLimitMin", "avgVoltage", "minVoltage", "minVoltageTime", "maxVoltage", "maxVoltageTime", "dateStr"};
                    //title = currentOrgName + "电压监测点月报表";
                    title = null;
                    templateFile = basePath + "/电压监测点日报表.xls";
                    break;
                case 4:
                case 14:
                case 24:
                    fileName = currentOrgName + "电压监测点月报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    dateFrom = request.getParameter("dateFrom");
                    dateTo = request.getParameter("dateTo");
                    condition = TheUtil.getPointSelectCondition(request);
                    list = ysjService.findAll(currentOrgCode, dateFrom, dateTo, condition, 0, 99999, lock);


                    fields = new String[]{"company", "subCompany", "name", "pointType", "pointType2", "rate", "upperLimitRate", "lowerLimitRate", "totalRunMin", "qualifiedMin",
                        "unqualifiedMin", "aboveUpperLimitMin", "underLowerLimitMin", "avgVoltage", "minVoltage", "minVoltageTime", "maxVoltage", "maxVoltageTime", "reportStatusCh", "dateStr", "reasonAnalyze", "treatWay", "completeCase", "note"};

                    for (Map<String, Object> map : list) {
                        Timestamp minVoltageTime = (Timestamp) (map.get("minVoltageTime"));
                        if (minVoltageTime != null) {
                            map.put("minVoltageTime", DateUtil.get(minVoltageTime));
                        }
                        Timestamp maxVoltageTime = (Timestamp) (map.get("maxVoltageTime"));
                        if (maxVoltageTime != null) {
                            map.put("maxVoltageTime", DateUtil.get(maxVoltageTime));
                        }
                    }

                    startRow = 1;
                    startCol = 0;

                    //title = currentOrgName + "电压监测点月报表";
                    title = null;
                    templateFile = basePath + "/电压监测点月报表.xls";
                    break;
                case 5:
                    fileName = currentOrgName + "电压监测点季度报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    int year = Integer.parseInt(request.getParameter("yearTo"));
                    int quarter = Integer.parseInt(request.getParameter("quarterTo"));
                    condition = TheUtil.getPointSelectCondition(request);
                    list = ysjService.findAllJsjLock(currentOrgCode, year, quarter, condition, 0, 9999);
                    String jidu = year + "年" + "第" + CommonUtil.getCharacterNumber(quarter) + "季度";
                    for (Map<String, Object> map : list) {

                        int reportStatusTemp = (Integer) (map.get("reportStatus"));
                        if (reportStatusTemp == 1) {
                            map.put("reportStatus", "上报");
                            //712991407 - 6116
                        } else {
                            map.put("reportStatus", "观测");
                        }

                        map.put("date", jidu);
                        Timestamp minVoltageTime = (Timestamp) (map.get("minVoltageTime"));
                        if (minVoltageTime != null) {
                            map.put("minVoltageTime", DateUtil.get(minVoltageTime));
                        }
                        Timestamp maxVoltageTime = (Timestamp) (map.get("maxVoltageTime"));
                        if (maxVoltageTime != null) {
                            map.put("maxVoltageTime", DateUtil.get(maxVoltageTime));
                        }
                    }

                    startRow = 1;
                    startCol = 0;
                    fields = new String[]{"company", "subCompany", "name", "pointType", "pointType2", "rate", "upperLimitRate", "lowerLimitRate", "totalRunMin", "qualifiedMin",
                        "unqualifiedMin", "aboveUpperLimitMin", "underLowerLimitMin", "avgVoltage", "minVoltage", "minVoltageTime", "maxVoltage", "maxVoltageTime", "reportStatus", "dateStr"};
                    //title = currentOrgName + "电压监测点季度报表";
                    title = null;
                    templateFile = basePath + "/电压监测点季度报表.xls";
                    break;
                case 6:
                    fileName = currentOrgName + "电压监测点年度报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    year = Integer.parseInt(request.getParameter("yearTo"));
                    condition = TheUtil.getPointSelectCondition(request);
                    list = ysjService.findAllNsjLock(currentOrgCode, year, condition, 0, 9999);

                    for (Map<String, Object> map : list) {

                        int reportStatusTemp = (Integer) (map.get("reportStatus"));
                        if (reportStatusTemp == 1) {
                            map.put("reportStatus", "上报");
                            //712991407 - 6116
                        } else {
                            map.put("reportStatus", "观测");
                        }
                        map.put("date", year);
                        Timestamp minVoltageTime = (Timestamp) (map.get("minVoltageTime"));
                        if (minVoltageTime != null) {
                            map.put("minVoltageTime", DateUtil.get(minVoltageTime));
                        }
                        Timestamp maxVoltageTime = (Timestamp) (map.get("maxVoltageTime"));
                        if (maxVoltageTime != null) {
                            map.put("maxVoltageTime", DateUtil.get(maxVoltageTime));
                        }
                    }

                    startRow = 1;
                    startCol = 0;
                    fields = new String[]{"company", "subCompany", "name", "pointType", "pointType2", "rate", "upperLimitRate", "lowerLimitRate", "totalRunMin", "qualifiedMin",
                        "unqualifiedMin", "aboveUpperLimitMin", "underLowerLimitMin", "avgVoltage", "minVoltage", "minVoltageTime", "maxVoltage", "maxVoltageTime", "reportStatus", "dateStr"};
                    //title = currentOrgName + "电压监测点年度报表";
                    title = null;
                    templateFile = basePath + "/电压监测点年度报表.xls";
                    break;
                case 41:    //实测率
                    fileName = currentOrgName + "监测点月实测率统计" + DateUtil.get(new Date(), "yyyyMMddHHmmss");
                    reportStatus = Integer.parseInt(request.getParameter("reportStatus"));
                    range = CommonWebUtil.getIntParameter(request.getParameter("range"), -1);
                    dateTo = request.getParameter("dateTo");
                    lock = request.getParameter("lock");
                    list = pointService.findUploadRate(currentOrgCode, dateTo, reportStatus, range, lock);
                    startRow = 2;
                    startCol = 0;
                    fields = new String[]{"orgName","A","PA","ARate"
                                 ,"B","PB","BRate"
                                 ,"C","PC","CRate"
                                 ,"D","PD","DRate"
                                 ,"DCS","PDCS","DCSRate","DCE","PDCE","DCERate"
                                 ,"DNS","PDNS","DNSRate","DNE","PDNE","DNERate"
                                 ,"total","PTotal","totalRate"};
                    title = null;
                    templateFile = basePath +"/监测点月实测率统计模板.xls";
                    break;

                case 42:    //覆盖率
                    fileName = currentOrgName + "覆盖率统计报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");
                    reportStatus = Integer.parseInt(request.getParameter("reportStatus"));
                    range = CommonWebUtil.getIntParameter(request.getParameter("range"), -1);
                    dateTo = request.getParameter("dateTo");
                    list = pointService.findCoverageRate(currentOrgCode, dateTo, reportStatus, range);
                    title=null;
                    startRow = 2;
                    startCol = 0;
                    fields = new String[]{"orgName","A","PA","ARate"
                                 ,"B","PB","BRate"
                                 ,"C","PC","CRate"
                                 ,"D","PD","DRate"
                                 ,"DCS","PDCS","DCSRate","DCE","PDCE","DCERate"
                                 ,"DNS","PDNS","DNSRate","DNE","PDNE","DNERate"
                                 ,"total","PTotal","totalRate"};
                    templateFile = basePath+"/覆盖率统计列表报表.xls";
                    break;
                case 70:
                    fileName = currentOrgName + "综合合格率日报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    String reportStatusParam = request.getParameter("reportStatus");
                    reportStatus = CommonWebUtil.getIntParameter(reportStatusParam, -1);

                    String rangeParam = request.getParameter("range");
                    range = CommonWebUtil.getIntParameter(rangeParam, -1);
                    dateTo = request.getParameter("dateTo");

                    dateFrom = dateTo.substring(0, 6) + "01";
                    //System.out.println("*" + dateTo + "*" + dateFrom);
                    list = rsjService.findAllOrgRsjReport(currentOrgCode, dateFrom, dateTo, range, reportStatus, lock);

                    for (Map<String, Object> map : list) {


                        Timestamp minVoltageTime = (Timestamp) (map.get("minVoltageTime"));
                        if (minVoltageTime != null) {
                            map.put("minVoltageTime", DateUtil.get(minVoltageTime));
                        }
                        Timestamp maxVoltageTime = (Timestamp) (map.get("maxVoltageTime"));
                        if (maxVoltageTime != null) {
                            map.put("maxVoltageTime", DateUtil.get(maxVoltageTime));
                        }
                    }

                    startRow = 4;
                    startCol = 0;
                    fields = new String[]{ "orgName", "rateTotal", "avgRateTotal", "planRate",
                        "rateA", "A", "avgRateA", "avgA",
                        "rateB", "B", "avgRateB", "avgB",
                        "rateC", "C", "avgRateC", "avgC",
                        "rateD", "D", "avgRateD", "avgD",
                        "rateDC", "DC", "avgRateDC", "avgDC",
                        "rateDN", "DN", "avgRateDN", "avgDN", "ABCD", "avgABCD"};
                    dateStr = DateUtil.changePattern(dateTo, "yyyyMMdd", "yyyy-MM-dd");
                    reportStr = TheUtil.getReportStr(reportStatus);
                    rangeStr = TheUtil.getRangeStr(range);
                    title = currentOrgName + dateStr + rangeStr + reportStr + "综合电压合格率统计表";
                    templateFile = basePath + "/综合电压质量合格率日报表.xls";
                    break;
                case 80:
                    fileName = currentOrgName + "综合合格率月报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    reportStatusParam = request.getParameter("reportStatus");
                    reportStatus = CommonWebUtil.getIntParameter(reportStatusParam, -1);

                    rangeParam = request.getParameter("range");
                    range = CommonWebUtil.getIntParameter(rangeParam, -1);
                    String yearTo = request.getParameter("yearTo");

                    Date now = new Date();
                    String thisMonth = DateUtil.get(now, "MM");
                    String thisYear = DateUtil.get(now, "yyyy");
                    if (!yearTo.equals(thisYear)) {
                        thisMonth = "12";
                    }
                    dateTo = yearTo + thisMonth;
                    dateFrom = yearTo + "01";
                    //System.out.println("*"+dateTo+"*"+dateFrom);
                    list = ysjService.findAllOrgYsjReportV2(currentOrgCode, dateFrom, dateTo, range, reportStatus,lock);


                    startRow = 4;
                    startCol = 0;
                    fields = new String[]{ "orgName", "rateTotal", "avgRateTotal", "planRate",
                        "rateA", "A", "avgRateA", "avgA",
                        "rateB", "B", "avgRateB", "avgB",
                        "rateC", "C", "avgRateC", "avgC",
                        "rateD", "D", "avgRateD", "avgD",
                        "rateDC", "DC", "avgRateDC", "avgDC",
                        "rateDN", "DN", "avgRateDN", "avgDN", "ABCD", "avgABCD"};
                    dateStr = DateUtil.changePattern(dateTo, "yyyyMM", "yyyy-MM");
                    reportStr = TheUtil.getReportStr(reportStatus);
                    rangeStr = TheUtil.getRangeStr(range);
                    title = currentOrgName + dateStr + rangeStr + reportStr + "综合电压质量合格率月报表";
                    templateFile = basePath + "/综合电压质量合格率月报表.xls";
                    break;
                case 90:
                    fileName = currentOrgName + "综合合格率季度报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    reportStatusParam = request.getParameter("reportStatus");
                    reportStatus = CommonWebUtil.getIntParameter(reportStatusParam, -1);

                    rangeParam = request.getParameter("range");
                    range = CommonWebUtil.getIntParameter(rangeParam, -1);
                    yearTo = request.getParameter("yearTo");
                    String quarterTo = request.getParameter("quarterTo");


                    dateTo = yearTo + quarterTo;
                    dateFrom = yearTo + "1";
                    //System.out.println("*"+dateTo+"*"+dateFrom);
                    list = ysjService.findAllOrgJsjReportV2(currentOrgCode, dateFrom, dateTo, range, reportStatus, lock);

                    startRow = 4;
                    startCol = 0;
                    fields = new String[]{"rn", "rateTotal", "avgRateTotal", "planRate",
                        "rateA", "A", "avgRateA", "avgA",
                        "rateB", "B", "avgRateB", "avgB",
                        "rateC", "C", "avgRateC", "avgC",
                        "rateD", "D", "avgRateD", "avgD",
                        "rateDC", "DC", "avgRateDC", "avgDC",
                        "rateDN", "DN", "avgRateDN", "avgDN", "ABCD", "avgABCD"};

                    dateStr = yearTo + "年第" + CommonUtil.getCharacterNumber(Integer.parseInt(quarterTo)) + "季度";
                    reportStr = TheUtil.getReportStr(reportStatus);
                    rangeStr = TheUtil.getRangeStr(range);
                    title = currentOrgName + dateStr + rangeStr + reportStr + "综合电压质量合格率季度报表";
                    templateFile = basePath + "/综合电压质量合格率季度报表.xls";
                    break;
                case 100:
                    fileName = currentOrgName + "综合合格率年度报表" + DateUtil.get(new Date(), "yyyyMMddHHmmss");

                    reportStatusParam = request.getParameter("reportStatus");
                    reportStatus = CommonWebUtil.getIntParameter(reportStatusParam, -1);

                    rangeParam = request.getParameter("range");
                    range = CommonWebUtil.getIntParameter(rangeParam, -1);
                    yearTo = request.getParameter("yearTo");

                    now = new Date();
                    thisMonth = DateUtil.get(now, "MM");
                    thisYear = DateUtil.get(now, "yyyy");
                    if (!yearTo.equals(thisYear)) {
                        thisMonth = "12";
                    }
                    dateTo = yearTo + thisMonth;
                    dateFrom = yearTo + "01";
                    //System.out.println("*"+dateTo+"*"+dateFrom);
                    list = ysjService.findAllOrgYsjReportV2(currentOrgCode, dateFrom, dateTo, range, reportStatus,lock);

                    startRow = 4;
                    startCol = 0;
                    fields = new String[]{ "rn", "rateTotal", "avgRateTotal", "planRate",
                        "rateA", "A", "avgRateA", "avgA",
                        "rateB", "B", "avgRateB", "avgB",
                        "rateC", "C", "avgRateC", "avgC",
                        "rateD", "D", "avgRateD", "avgD",
                        "rateDC", "DC", "avgRateDC", "avgDC",
                        "rateDN", "DN", "avgRateDN", "avgDN", "ABCD", "avgABCD"};
                    dateStr = yearTo + "年";
                    reportStr = TheUtil.getReportStr(reportStatus);
                    rangeStr = TheUtil.getRangeStr(range);
                    title = currentOrgName + dateStr + rangeStr + reportStr + "综合电压质量合格率年度报表";
                    templateFile = basePath + "/综合电压质量合格率年度报表.xls";
                    break;
            }
            response.resetBuffer();          //利用输出输入流导出文件             
            String contentType = "application/vnd.ms-excel";//定义导出文件的格式的字符串
            fileName=fileName+".xls";
            String recommendedName = new String(fileName.getBytes(), "iso_8859_1");//设置文件名称的编码格式
            response.setContentType(contentType);//设置导出文件格式
            response.setHeader("Content-Disposition", "attachment; filename=\"" + recommendedName + "\"");//        
            new ExcelUtil().getExcelFileFromTemplate(title, list, fields, out, templateFile, startRow, startCol);
            out.flush();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
